package com.wenhui.schoolyardinfo.main;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.qmuiteam.qmui.widget.QMUITopBar;
import com.wenhui.schoolyardinfo.R;
import com.wenhui.schoolyardinfo.base.BaseActivity;
import com.wenhui.schoolyardinfo.customview.MineLazyViewPager;
import com.wenhui.schoolyardinfo.firstpage.FirstPageFragment;
import com.wenhui.schoolyardinfo.main.adapter.TabFragmentPagerAdapter;
import com.wenhui.schoolyardinfo.manager.LogManager;
import com.wenhui.schoolyardinfo.message.MessageFragment;
import com.wenhui.schoolyardinfo.mine.MineFragment;
import com.wenhui.schoolyardinfo.release.ReleaseFragment;
import com.wenhui.schoolyardinfo.square.SquareFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * author    : Urasaki
 * e-mail    : 1164688204@qq.com
 * date      : 2019/6/12B 10:26
 * introduce :
 */

public class MainActivity extends BaseActivity {

    private static final String TAG = "MainActivity";
    @BindView(R.id.mine_view_pager)
    MineLazyViewPager mineViewPager;
    @BindView(R.id.imv_home_page)
    ImageView imvHomePage;
    @BindView(R.id.tev_home_page)
    TextView tevHomePage;
    @BindView(R.id.layout_home_page)
    RelativeLayout layoutHomePage;
    @BindView(R.id.imv_square)
    ImageView imvSquare;
    @BindView(R.id.tev_square)
    TextView tevSquare;
    @BindView(R.id.layout_square)
    RelativeLayout layoutSquare;
    @BindView(R.id.imv_release)
    ImageView imvRelease;
    @BindView(R.id.layout_release)
    RelativeLayout layoutRelease;
    @BindView(R.id.imv_message)
    ImageView imvMessage;
    @BindView(R.id.tev_message)
    TextView tevMessage;
    @BindView(R.id.layout_message)
    RelativeLayout layoutMessage;
    @BindView(R.id.imv_mine)
    ImageView imvMine;
    @BindView(R.id.tev_mine)
    TextView tevMine;
    @BindView(R.id.layout_mine)
    RelativeLayout layoutMine;
    @BindView(R.id.layout_main)
    LinearLayout layoutMain;
    private List<Fragment> fragmentList;
    private TabFragmentPagerAdapter fragmentPagerAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);

        initData();
        initViews();
    }

    @Override
    protected void initData() {
        fragmentList = new ArrayList<>();
        fragmentList.add(new FirstPageFragment());
        fragmentList.add(new SquareFragment());
        fragmentList.add(new ReleaseFragment());
        fragmentList.add(new MessageFragment());
        fragmentList.add(new MineFragment());

    }

    @Override
    protected void initViews() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            //实现状态栏图标和文字颜色为暗色
            getWindow().getDecorView().setSystemUiVisibility(
                    View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        }

        imvHomePage.setColorFilter(getResources().getColor(R.color.colorBlueA));
        imvSquare.setColorFilter(getResources().getColor(R.color.colorGrayA));
        imvMessage.setColorFilter(getResources().getColor(R.color.colorGrayA));
        imvMine.setColorFilter(getResources().getColor(R.color.colorGrayA));

        fragmentPagerAdapter = new TabFragmentPagerAdapter(getSupportFragmentManager(), fragmentList);
        mineViewPager.setAdapter(fragmentPagerAdapter);
    }

    private void initButton() {
        imvHomePage.setColorFilter(getResources().getColor(R.color.colorGrayA));
        imvSquare.setColorFilter(getResources().getColor(R.color.colorGrayA));
        imvMessage.setColorFilter(getResources().getColor(R.color.colorGrayA));
        imvMine.setColorFilter(getResources().getColor(R.color.colorGrayA));
        tevHomePage.setTextColor(getResources().getColor(R.color.colorGrayA));
        tevSquare.setTextColor(getResources().getColor(R.color.colorGrayA));
        tevMessage.setTextColor(getResources().getColor(R.color.colorGrayA));
        tevMine.setTextColor(getResources().getColor(R.color.colorGrayA));
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        LogManager.i(TAG, "onActivityResult");
        LogManager.i(TAG, "resultCode*****" + resultCode);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

    }

    @OnClick({R.id.layout_home_page, R.id.layout_square, R.id.layout_release, R.id.layout_message, R.id.layout_mine})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.layout_home_page:
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                    //实现状态栏图标和文字颜色为暗色
                    getWindow().getDecorView().setSystemUiVisibility(
                            View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
                }
                initButton();
                imvHomePage.setImageResource(R.mipmap.icon_home_page);
                imvHomePage.setColorFilter(getResources().getColor(R.color.colorBlueA));
                tevHomePage.setTextColor(getResources().getColor(R.color.colorBlueA));
                mineViewPager.setCurrentItem(0);
                layoutMain.setBackgroundColor(getResources().getColor(R.color.colorWhiteA));
                break;
            case R.id.layout_square:
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                    //实现状态栏图标和文字颜色为暗色
                    getWindow().getDecorView().setSystemUiVisibility(
                            View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
                }
                initButton();
                imvSquare.setImageResource(R.mipmap.icon_square);
                imvSquare.setColorFilter(getResources().getColor(R.color.colorBlueA));
                tevSquare.setTextColor(getResources().getColor(R.color.colorBlueA));
                mineViewPager.setCurrentItem(1);
                layoutMain.setBackgroundColor(getResources().getColor(R.color.colorWhiteA));
                break;
            case R.id.layout_release:
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                    //实现状态栏图标和文字颜色为暗色
                    getWindow().getDecorView().setSystemUiVisibility(
                            View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
                }
                initButton();
                imvRelease.setImageResource(R.mipmap.icon_release);
                mineViewPager.setCurrentItem(2);
                layoutMain.setBackgroundColor(getResources().getColor(R.color.colorWhiteA));
                break;
            case R.id.layout_message:
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                    //实现状态栏图标和文字颜色为暗色
                    getWindow().getDecorView().setSystemUiVisibility(
                            View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
                }
                initButton();
                imvMessage.setImageResource(R.mipmap.icon_message);
                imvMessage.setColorFilter(getResources().getColor(R.color.colorBlueA));
                tevMessage.setTextColor(getResources().getColor(R.color.colorBlueA));
                layoutMain.setBackgroundColor(getResources().getColor(R.color.colorWhiteA));
                mineViewPager.setCurrentItem(3);
                break;
            case R.id.layout_mine:
                //设置状态栏文字颜色及图标为浅色
                getWindow().getDecorView().setSystemUiVisibility(
                        View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
                initButton();
                imvMine.setImageResource(R.mipmap.icon_mine);
                imvMine.setColorFilter(getResources().getColor(R.color.colorBlueA));
                tevMine.setTextColor(getResources().getColor(R.color.colorBlueA));
                layoutMain.setBackgroundColor(getResources().getColor(R.color.colorBlackE));
                mineViewPager.setCurrentItem(4);
                break;
        }
    }
}
